import logging
from automationserver import AutomationServer
import msvcrt
import time
import sys
import locale

def GetExitsFlag():
    if msvcrt.kbhit() and msvcrt.getch() == 'q':
        return True
    return False

def main():
    try:
        lang, code = locale.getdefaultlocale()
        reload(sys)
        sys.setdefaultencoding(code)
        server = AutomationServer()
        
        if server.Init() == False:
            return
        
        while GetExitsFlag() == False:
            server.Loop()
            time.sleep(0.2)
        
        server.Uninit()
        
        logging.info('server exit')
    except Exception as e:
        logging.exception(e)
        
        

if __name__ == '__main__':
    main()
    print('finish')